﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using YXShop.BLL.Admin;

namespace YXShop.Web.admin.systeminfo
{
    public partial class bankinfo_edit : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {   
            if(!IsPostBack)
            {
                YXShop.Common.PromptInfo.Popedom("010003002", "对不起，您没有权限进行编辑");
                YXShop.Common.PromptInfo.Popedom("010003004", "对不起，您没有权限进行编辑");
                if (ChangeHope.WebPage.PageRequest.GetInt("id") > 0)
                {
                    BindInfo(ChangeHope.WebPage.PageRequest.GetInt("id"));
                }
                InitWebControl();
            }
           
        }

        #region 验证
        private void InitWebControl()
        {
            ChangeHope.WebPage.WebControl.Validate(this.txtSort, "输入数字作为排序，值越小越靠前", "isint", "必填", "该项为必填项");
            ChangeHope.WebPage.WebControl.Validate(this.txtBankName, "输入银行的名字", "isnull", "必填", "该项为必填项");       
            this.Form.Attributes.Add("onsubmit", "return CheckForm()");
        }
        #endregion

        protected void BindInfo(int id)
        {
            YXShop.BLL.SystemInfo.BankInfo bll = new YXShop.BLL.SystemInfo.BankInfo();
            YXShop.Model.SystemInfo.BankInfo model = bll.GetModelByID(id);
            this.txtBankName.Text = model.BankName;
            ViewState["date"] = model.AddDate.ToString();
            ViewState["ID"] = model.ID.ToString();
            this.txtSort.Text = model.Sort.ToString();
            this.ddlState.SelectedValue = model.Sort.ToString();
        }

        protected void lbSave_Click(object sender, EventArgs e)
        {
            YXShop.BLL.SystemInfo.BankInfo bll = new YXShop.BLL.SystemInfo.BankInfo();
            YXShop.Model.SystemInfo.BankInfo model = new YXShop.Model.SystemInfo.BankInfo();
            YXShop.Model.Admin.AdminInfo adminModel = (YXShop.Model.Admin.AdminInfo)YXShop.Common.AdministrorManager.Get();
            model.BankName = this.txtBankName.Text;
            model.AdminId = adminModel.AdminName;
            model.Sort = Convert.ToInt32(this.txtSort.Text.Trim());
            model.State = Convert.ToInt32(this.ddlState.SelectedValue);
            model.BankLogo = string.Empty;
            if (ViewState["ID"]!=null)
            {
                model.AddDate = Convert.ToDateTime(ViewState["date"].ToString());
                model.ID = Convert.ToInt32(ViewState["ID"].ToString());
                bll.Amend(model);
            }
            else
            {
                model.AddDate = DateTime.Now;
                bll.Add(model);
            }
            this.ltlMsg.Text = "操作成功";
            this.pnlMsg.Visible = true;
            this.pnlMsg.CssClass = "actionOk";
            return;
        }
    }
}
